package com.longe.controller;

import com.longe.common.Result;
import com.longe.entity.User;
import com.longe.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author longe
 * @since 2020-05-23
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("register")
    public Result<Object> register(@RequestBody User user){
        return userService.register(user);
    }

    @PostMapping("login")
    public Result<User> login(@RequestBody User user){
        return userService.login(user);
    }

    @PostMapping("upload")
    public Result<User> upload(MultipartFile file, Integer userId){
        return userService.upload(file, userId);
    }

    @PostMapping("nickname")
    public Result<User> updateNickname(@RequestBody User user){
        return userService.updateNickname(user);
    }

    @PostMapping("username")
    public Result<User> findByUsername(@RequestBody User user){
        return userService.findByUsername(user);
    }
}
